package com.hrg.demo.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author shenzq
 */
@Data
@Component
@ConfigurationProperties(prefix = "images.param.cleanup")
public class FileCleanupProperties {

    private boolean enabled ;
    private String cron;
    private int filenameLength;
    private int expireDays;

    @PostConstruct
    public void validate() {
        if(cron == null || cron.trim().isEmpty()){
            throw new IllegalArgumentException("cron表达式不能为空！");
        }
        // 验证cron表达式
        if (!CronValidator.isValid(cron)) {
            throw new IllegalArgumentException("无效的cron表达式: " + cron);
        }
        if (filenameLength <= 0) {
            throw new IllegalArgumentException("文件名长度阈值必须大于0");
        }
        if (expireDays <= 0) {
            throw new IllegalArgumentException("过期天数必须大于0");
        }
    }
}
